Skip to content

Emit 'plotly_webglcontextlost' event on WebGL context lost #2986

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Sep 11, 2018

Conversation

etpinard
Copy link
Contributor

@etpinard etpinard commented Sep 7, 2018

cc @alexcjohnson

I'm not sure if there's a way to actually test this.

This PR makes regl-based graphs emit an event on WebGL context lost from one of our canvases.

Note that gl3 already sort of does this:

scene.glplot.canvas.addEventListener('webglcontextlost', function(ev) {
Lib.warn('Lost WebGL context.');
ev.preventDefault();
});

but logs something instead of emitting an event. Personally, I think emitting an event is better, but maybe consistency with gl3d is best (this is, before the v2 push).

- with event data containing the original event and
  the canvas 'key' to determine which canvas lost its context.
@etpinard etpinard added this to the v1.41.0 milestone Sep 7, 2018
@alexcjohnson
Copy link
Collaborator

Personally, I think emitting an event is better, but maybe consistency with gl3d is best

👍 for events in all cases.

I'm not sure if there's a way to actually test this.

Maybe not to cause a real context loss, but can we mock the native event, just so we can be sure the plotly event is triggered on any of the canvases losing their context?

@etpinard
Copy link
Contributor Author

Maybe not to cause a real context loss, but can we mock the native event, just so we can be sure the plotly event is triggered on any of the canvases losing their context?

Good call. Done in -> 7e282c3

setTimeout(reject, 10);

var ev = new window.WebGLContextEvent('webglcontextlost');
var canvas = gd.querySelector('.gl-canvas-context');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant by "triggered on any of the canvases losing their context" is, for this one plot we make 3 canvases, each with its own webgl context... any of them could in principle lose its context, right?

> gd.querySelectorAll('canvas')
NodeList(3) [
    canvas.gl-canvas.gl-canvas-context,
    canvas.gl-canvas.gl-canvas-focus,
    canvas.gl-canvas.gl-canvas-pick
]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, you caught me being lazy.

Better tests in 905956a

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even better tests in 3a38d73

@alexcjohnson
Copy link
Collaborator

💃
Make sure we add a mention of this to https://plot.ly/javascript/plotlyjs-events/

@etpinard
Copy link
Contributor Author

Make sure we add a mention of this to https://plot.ly/javascript/plotlyjs-events/

will be in plotly/documentation#1085

@etpinard etpinard merged commit cbbba35 into master Sep 11, 2018
@etpinard etpinard deleted the webgl-oncontext-loss branch September 11, 2018 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants